library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity regindicey is
Port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
EY : in std_logic_vector (2 downto 0);
Y : in std_logic_vector (2 downto 0);
busdatosaltain : in std_logic_vector (7 downto 0);
busdatosbajain : in std_logic_vector (7 downto 0);
Bus16 : out std_logic_vector (15 downto 0) := "ZZZZZZZZZZZZZZZZ";
busdatosalta: out std_logic_vector (7 downto 0) := "ZZZZZZZZ";
busdatosbaja: out std_logic_vector (7 downto 0) := "ZZZZZZZZ";
YN : out std_logic;
YZ : out std_logic);

end regindicey;


architecture Behavioral of regindicey is
	constant s0 : std_logic := '0';
	shared variable x : std_logic_vector (15 downto 0) := "0000000000000000";
	shared variable w : std_logic;
	shared variable z : std_logic_vector (15 downto 0) := "0000000000000000";
	--shared variable busdatosalta: std_logic_vector (7 downto 0);
	--shared variable busdatosbaja: std_logic_vector (7 downto 0);
	

begin
process(EY,Y,clk)
begin
if reset ='1' then x := "0000000000000000";
else 
if rising_edge (clk) then
			
			if(Y = "000")
				then 
					x := x;
			elsif (Y = "001")
				then 
					x := x + 1;	
			elsif (Y = "010")
				then 
					x := x - 1;	
			elsif (Y = "011")
				then 
					x(7 downto 0) := busdatosbajain;
			elsif (Y = "100")
				then 
					x(15 downto 8) := busdatosaltain;	
			elsif (Y = "101")
				then 
					x := busdatosaltain & busdatosbajain;
			elsif (Y = "110")     --corrimiento a la izquierda
				then 
					x := x(15 downto 1) & s0;
			elsif (Y = "111")     --corrimiento a la derecha
				then 
					x := s0 & x(14 downto 0);
			end if;

			
			if(EY = "111")
				then 
					bus16 <= "ZZZZZZZZZZZZZZZZ";
			elsif (EY = "110") 		
				then
					busdatosbaja <= x(7 downto 0);
			elsif (EY = "101") 		
				then	
					busdatosalta <= x(15 downto 8);
			elsif (EY = "011")
				then	bus16 <= x;
			end if;
			w := x(15);
			z := x;
			if w = '1'
				then YN <= '1';
			else YN <='0';
			end if;
			if z= "0000000000000000"
				then YZ <= '1';
			else YZ <='0';
			end if;
end if;
end if;
end process;	


end Behavioral;